package com.lm.protobuf.controller;

import com.lm.protobuf.model.User;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping(value = "/{id}", produces = "application/x-protobuf")
    public User getUser(@PathVariable int id) {
        return User.newBuilder()
                .setId(id)
                .setName("张三")
                .setEmail("zhangsan@example.com")
                .build();
    }

    @PostMapping(consumes = "application/x-protobuf", produces = "application/x-protobuf")
    public User createUser(@RequestBody User user) {
        System.out.println("接收到用户：" + user.getName());
        return user;
    }
}
